<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

//print_r($_POST);



//2 choose accordingly which part print out 
$lpp=14;
$rangeBegin=0;
$rangeEnd="";
foreach($_POST as $key =>$value)
{
    if(substr_count($key,"counter")>0){		
		if($value >= $rangeBegin and $rangeEnd=="") {$rangeBegin=$value; $rangeEnd = $rangeBegin;}
		elseif($value > $rangeEnd) {$rangeEnd = $value;}
		}	
	
	}

//echo $rangeBegin."|".$rangeEnd;
//3 if more than even number , ask which label to print 
$totalLabel = 0;
for($i=$rangeBegin;$i<=$rangeEnd;$i++){
	if(isset($_POST['choice'.$i])){
		$totalLabel+=$_POST['qt'.$i];
		}
	
	}
echo $totalLabel;
echo "show some summary";
$postData = base64_encode(gzcompress(serialize($_POST)));	

?>
<form action="eb3.php" method="post" enctype="multipart/form-data" name="finalform">
<input name="postdata" type="hidden" value="<?php echo $postData?>" />
<input name="rangebegin" type="hidden" value="<?php echo $rangeBegin?>" />
<input name="rangeend" type="hidden" value="<?php echo $rangeEnd?>" />
<input name="totallabel" type="hidden" value="<?php echo $totalLabel?>" />
<?php
$lleft=$totalLabel%$lpp;
if($lleft!=0){

for($i=0;$i<$lpp;$i++){
?>
<input name="position<?php echo $i;?>"  type="checkbox" value="<?php echo $i;?>"
<?php
if($i<=$lleft-1){
?>
checked="checked"
<?php }?>
 />
<?php	
if(($i+1)%2==0) {echo "<br />";}
      }
}
	
//4  product one single html 

?>
<input name="" type="submit" />
</form>
</body>
</html>